<%@ taglib uri="/WEB-INF/translator.tld" prefix="trans" %>
<%@ page contentType="text/html; charset=iso-8859-1" %>
<%@ page import="ro.gateway.aida.servlet.*" %>
<%@ page import="ro.gateway.aida.obj.db.*" %>
<%@ page import="ro.gateway.aida.srv.ICFService" %>
<%@ page import="ro.gateway.aida.servlet.Constants" %>
<%@ page import="java.util.Hashtable" %>
<%@ page import="ro.gateway.aida.utils.HttpUtils" %>
<%@ page import="ro.gateway.aida.srv.EditorServlet" %>
<%@ page import="ro.gateway.aida.obj.Person" %>
<%@ page import="java.util.*" %>

<%
 //init translator

String lang = HttpUtils.getValidTrimedString(request, "lang","ro");

//vreau sa scap de asta - tre sa generez lista de tipuri de orgs

 Hashtable bean = (Hashtable) request.getAttribute(PersSelectorServlet.PNAME_BEAN);
    if (bean == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
    }
Vector selectedList=(Vector)bean.get(PersSelectorServlet.PNAME_SELECTEDPERS);
    if (selectedList == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
    }

String perskey =(String) bean.get(PersSelectorServlet.PNAME_PERSKEY);
Vector list=(Vector)bean.get(PersSelectorServlet.PNAME_PERSLIST);

    String key = (String) bean.get(PersSelectorServlet.PNAME_KEY);
    String ctx = request.getContextPath();

String editing_action = (String) bean.get(PersSelectorServlet.PNAME_ACTION);

Object screen = request.getAttribute(EditPersonServlet.PNAME_SCREEN);
    String[] errors = (String[]) request.getAttribute(EditPersonServlet.PNAME_ERRORS);

String verbose=(String)bean.get(PersSelectorServlet.PNAME_VERBOSE);


%>

<trans:initPage module="persel" />
<html>
<head>
<title>Local Projects Database - Person Selector</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="../alf.css" type="text/css">
</head>

<body bgcolor="#FFFFFF" text="#000000" topmargin=0 leftmargin=0>



<% if (PersSelectorServlet.PV_SCR_READY.equals(screen)) { %>

<script language="javascript">
opener.after_pers_sel();window.close();
</script>

<%  } else  if (EditPersonServlet.PV_SCR_EDIT.equals(screen)) { %>
<!-- Edit the form -->
<script language="javascript">
    function submit_theform(action,param) {
        document.theform.sbutton.disabled=1;
        document.theform.cbutton.disabled=1;
        document.theform.clbutton.disabled=1;
document.theform.rbutton.disabled=1;
        document.theform.action.value=action;
document.theform.param.value=param;
        document.theform.submit();
}
  function submit_thesearch(action) {
        if (formCheck()==false) return false;
        document.theform.sbutton.disabled=1;
document.theform.rbutton.disabled=1;
        document.theform.cbutton.disabled=1;
        document.theform.srcbutton.disabled=1;
        document.theform.action.value=action;
        document.theform.submit();
}

</script>
<br>
<form name="theform" method="post" action="<%=ctx%>/pers/sel">
<input type="hidden" name="<%=EditorServlet.PNAME_KEY%>" value="<%=key%>" />
<input type="hidden" name="param" value="" />
<input type="hidden" name="lang" value="<%=lang%>" />
<input type="hidden" name="perskey" value="<%=perskey%>" />
<input type="hidden" name="<%=EditorServlet.PNAME_ACTION%>" value="<%=EditorServlet.PV_ACTION_EDIT%>" />
<% if (errors != null) { %>
    <tr>
        <td colspan="2">
        Errors!
        <% for (int i = 0; i < errors.length; i++) { %>
        <%=errors[i]%>
        <% } %>
    </td>
    </tr>
<% } %>


  <table align="center" class="text_searchbold" bgcolor="#3399CC" width="90%" cellpadding="5" cellspacing="1" border="0">
     <tr><td> <span class="textalb"><trans:showPageMessage label="persel.involvedpeoplesel" /></span>
	<tr>
      <td bgcolor="#FFFFFF">
         <trans:showPageMessage label="persel.persname" />:
<input type="text" name="search" value="" size=10>
        <input name="srcbutton" type="button" value="<trans:showPageMessage label="persel.search" hide_link="true" />" onClick="javascript:submit_thesearch('<%=EditorServlet.PV_ACTION_EDIT%>');" class="buton">
      </td>
<tr>
      <td bgcolor="#FFFFFF">
<% if (!list.isEmpty()) { %>
        <select name="perselect">
<%
for (Enumeration e = list.elements() ; e.hasMoreElements() ;) {
Person pers=(Person)e.nextElement();
%>
<option value="<%=pers.getId()%>"><%=pers.getName()%></option>
<% } %>
</select>
<% } %>
        &nbsp;
        <input name="sbutton" type="button" value="<trans:showPageMessage label="persel.add" hide_link="true" />" onClick="javascript:submit_theform('<%=EditorServlet.PV_ACTION_EDIT%>','');" class="buton">
        <input name="rbutton" type="button" value="<trans:showPageMessage label="persel.showallpeople" hide_link="true" />" onClick="javascript:submit_theform('<%=EditorServlet.PV_ACTION_CONFIRM%>','showall');" class="buton">

</td>
      <tr><td bgcolor="#FFFFFF">


		<table width="95%" border="0" cellpadding="3" cellspacing="1" bgcolor="#efefef" class="text_searchbold" align="center">
          <%
for(int x=0;x<selectedList.size();x++) {
Person pers=(Person)selectedList.get(x);
%>
          <tr>
            <td bgcolor="#f9f9f9" class="text_search"><%=pers.getFirstNames()%>&nbsp;<%=pers.getLastName()%></td>
          </tr>
            <% } %>
        </table>

        <br>
        <input name="clbutton" type="button" value="<trans:showPageMessage label="persel.clear" hide_link="true" />" onClick="javascript:submit_theform('<%=EditorServlet.PV_ACTION_CONFIRM%>','clear');" class="buton">
</td>
</tr>
<tr>
      <td bgcolor="#FFFFFF">

        &nbsp;&nbsp;&nbsp;&nbsp;<input name="cbutton" type="button" value="<trans:showPageMessage label="persel.save" hide_link="true" />" onClick="javascript:submit_theform('<%=EditorServlet.PV_ACTION_SAVE%>','');" class="butonsave">.
<% if ("all".equals(verbose)) {%>
<trans:showPageMessage label="persel.listingallpeople" />
<% } %>
<% if ("byOrg".equals(verbose)) {%>
Listing all people assigned to an organization
<% } %>
<% if ("unassigned".equals(verbose)) {%>
Listing all people unassigned to an organization
<% } %>

</td>


</tr>

</table>

</form>
<% } %>




<script language="javascript">
function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function



function noBlank(strItem, strMessage)
{
var strValue
strValue=eval("document.theform." + strItem + ".value");
strValue=trim(strValue);
if(strValue=="")
    {
    alert("The " + strMessage + " field cannot be blank!");
    return false;
    }
return true;
}

function tooLong(strItem, len, strMessage)
{
var lenValue
lenValue=eval("document.theform." + strItem + ".value.length");
if(lenValue>len)
    {
    alert("The " + strMessage + " field is too long!");
    return false;
    }
return true;
}


 function formCheck()
{
var ret=true;
ret&=noBlank("search","Search");
ret&=tooLong("search",100,"Search");
return ret;
}


</script>


</body>
</html>
